/**	
 * タイトル：	.properties文件读取类
 * 説明：    	
 *			
 * 会社名：	紹興日創軟件有限公司
 * 変更履歴：	2014/08/13 NIS 何
 *			新規作成
 *
 */
package com.nissoft.framework.message;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * @author NIS 何
 * @version 1.0
 */
public class PropertyMessageReader extends
		FileMessageReader<Map<String, String>> {

	@Override
	protected String[] getDefaultExtensions() {
		return new String[] { ".properties" };
	}

	@Override
	protected String getFileKey(String pattern) {

		int lastSeparator = pattern.lastIndexOf(separator);
		return pattern.substring(0, lastSeparator == -1 ? pattern.length()
				: lastSeparator);
	}

	@Override
	public Map<String, String> loadFile(File file) throws IOException {

		Properties prop = new Properties();
		InputStreamReader isr = new InputStreamReader(
				new FileInputStream(file), encoding);
		prop.load(isr);
		isr.close();
		Map<String, String> data = new HashMap<String, String>();
		Set<Object> set = prop.keySet();
		for (Object s : set) {
			String key = s.toString();
			data.put(key, prop.getProperty(key));
		}
		return data;
	}

	@Override
	public String readInternal(String pattern, Map<String, String> e) {

		int lastSeparator = pattern.lastIndexOf(separator);
		String key = pattern.substring(lastSeparator + 1);
		return e.get(key);
	}

	public static void main(String[] args) throws IOException {

		// Properties prop = new Properties();
		// InputStreamReader isr = new InputStreamReader(new FileInputStream(
		// new File("E:\\message\\jdbc.properties")), "utf-8");
		// prop.load(isr);
		// Set<Entry<Object, Object>> s = prop.entrySet();
		// Enumeration<Object> e = prop.keys();
		// Enumeration<?> pn = prop.propertyNames();
		// Set<String> spn = prop.stringPropertyNames();
		// System.out.println(s);
		// System.out.println(e);
		// System.out.println(pn);
		// System.out.println(spn);
		String jin = "﻿#";
		System.out.println(jin.codePointAt(0));
		System.out.println(jin.codePointAt(1));
	}
}
